package top.skihub.mapper.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

    @Configuration
    public class CorsConfig {
        @Bean
        public WebMvcConfigurer corsConfigurer() {
            return new WebMvcConfigurer() {
                @Override
                public void addCorsMappings(CorsRegistry registry) {
                    registry.addMapping("/**") // 映射所有路径
                            .allowedOrigins("http://backend-net/:8080", "http://vue-net/:7000", "http://vue-net/:80", "http://vue-net/81") // 允许前端访问的源
                            .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") // 允许的方法
                            .allowedHeaders("*") // 允许的头部字段
                            .allowCredentials(true); // 允许携带凭证
                }
            };
        }
    }


